package com.manage.modules.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.common.annotation.Log;
import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.enums.BusinessType;
import com.manage.modules.vo.TBaseFaultTypeVo;
import com.manage.modules.bo.TBaseFaultTypeQueryBo;
import com.manage.modules.bo.TBaseFaultTypeAddBo;
import com.manage.modules.bo.TBaseFaultTypeEditBo;
import com.manage.modules.service.ITBaseFaultTypeService;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 故障类型Controller
 *
 * @author wx
 * @date 2021-08-16
 */
@Api(value = "故障类型控制器", tags = {"故障类型管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/modules/faultType")
public class TBaseFaultTypeController extends BaseController {

    private final ITBaseFaultTypeService iTBaseFaultTypeService;

    /**
     * 查询故障类型列表
     */
    @ApiOperation("查询故障类型列表")
    @PreAuthorize("@ss.hasPermi('modules:faultType:list')")
    @GetMapping("/list")
    public TableDataInfo<TBaseFaultTypeVo> list(TBaseFaultTypeQueryBo bo) {
        startPage();
        List<TBaseFaultTypeVo> list = iTBaseFaultTypeService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出故障类型列表
     */
    @ApiOperation("导出故障类型列表")
    @PreAuthorize("@ss.hasPermi('modules:faultType:export')")
    @Log(title = "故障类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TBaseFaultTypeVo> export(TBaseFaultTypeQueryBo bo) {
        List<TBaseFaultTypeVo> list = iTBaseFaultTypeService.queryList(bo);
        ExcelUtil<TBaseFaultTypeVo> util = new ExcelUtil<TBaseFaultTypeVo>(TBaseFaultTypeVo.class);
        return util.exportExcel(list, "故障类型");
    }

    /**
     * 获取故障类型详细信息
     */
    @ApiOperation("获取故障类型详细信息")
    @PreAuthorize("@ss.hasPermi('modules:faultType:query')")
    @GetMapping("/{faultTypeId}")
    public AjaxResult<TBaseFaultTypeVo> getInfo(@PathVariable("faultTypeId") Long faultTypeId) {
        return AjaxResult.success(iTBaseFaultTypeService.queryById(faultTypeId));
    }

    /**
     * 新增故障类型
     */
    @ApiOperation("新增故障类型")
    @PreAuthorize("@ss.hasPermi('modules:faultType:add')")
    @Log(title = "故障类型", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TBaseFaultTypeAddBo bo) {
        return toAjax(iTBaseFaultTypeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改故障类型
     */
    @ApiOperation("修改故障类型")
    @PreAuthorize("@ss.hasPermi('modules:faultType:edit')")
    @Log(title = "故障类型", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TBaseFaultTypeEditBo bo) {
        return toAjax(iTBaseFaultTypeService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除故障类型
     */
    @ApiOperation("删除故障类型")
    @PreAuthorize("@ss.hasPermi('modules:faultType:remove')")
    @Log(title = "故障类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{faultTypeIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] faultTypeIds) {
        return toAjax(iTBaseFaultTypeService.deleteWithValidByIds(Arrays.asList(faultTypeIds), true) ? 1 : 0);
    }
}
